$(function () {
    $('#login-btn').on('click', function () {
        var username = $('[name=username]').val().trim();
        var password = $('[name=password]').val().trim();
        if (!username) {
            mui.toast("请输入用户名");
        }
        if (!password) {
            mui.toast("请输入密码");
        }
        $.ajax({
            type: "post",
            url: "/user/login",
            data: {
                username,
                password
            },
            beforeSend: function () {
                $('#login-btn').text('正在登录中...')
            },
            success: function (res) {
                $('#login-btn').text('登录')
                console.log(res);
                if (res.error) {
                    mui.toast(res.message);
                } else {
                    mui.toast('登录成功');
                    location.href = 'user.html'
                }
            }
        });
    })
})